﻿<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@page import="com.mtbu.comm.Util"%>
<%@page import="com.util.SuperString"%>
<%@page import="com.util.SuperPage"%>
<%@page import="com.util.SuperFile"%>
<%@page import="com.mtbu.dao.DAOManager"%>
<%@page import="com.mtbu.bean.SysFunc"%>
<%@page import="my.myorm.tool.jdbc.SQLExecutor"%>
<%@page import="my.myorm.tool.jdbc.SQLManager"%>
<%@page import="my.myorm.tool.jdbc.ResultList"%>
<%@page import="com.mtbu.bean.SysRole"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.mtbu.bean.SysUser"%>
<%@page import="my.myorm.tool.jdbc.DefaultBean"%>
<%session.setAttribute("cache","y");%>
<%@include file="sys_commcheck.jsp"%>
<%
    if(!Constant_isAdmin){
        Util.callInfo("没有操作权限！",request,response);
        return;
    }
	String mid = SuperString.notNullTrim(request.getParameter("mid"));
    String act = SuperString.notNullTrim(request.getParameter("act"));
    if(!act.equalsIgnoreCase("mod")) act = "add";
    boolean isAdd = act.equalsIgnoreCase("add");
    boolean isMod = act.equalsIgnoreCase("mod");
    String titletext = isAdd ? "新增" : "修改";

    String curFile = SuperPage.getCurURLFile(request);
    String modFileDo = SuperFile.getFileName(curFile) + "do.jsp";
    String curName = "系统功能";

    int id=SuperString.getInt(request.getParameter("id"));
    if(act.equalsIgnoreCase("mod") && id<=0){
        Util.callInfo("错误的调用方法！",request,response);
        return;
    }

    SysFunc func= isMod? DAOManager.sysFuncDao.findSysFunc(id):new SysFunc();
    if(isMod && func==null){
        Util.callInfo("该功能不存在！", request, response);
        return;
    }

    SQLExecutor dbconn = SQLManager.getSQLExecutor();
    String sql = "select r.*,f.id fid from sys_role r left join sys_func_map f on (r.rolename=f.urname and f.fid=? and f.type=1)";
    dbconn.addParam(id);
    ResultList list = dbconn.query(sql, true, null);
    String strOnSubmit = SuperPage.getOnSubmitCode("funcid,R;funcname,R", "");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>无标题文档</title>
<link href="css/common.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/comm.js"></script>
<script language="javascript">
function click_role(obj){
    if(obj==null) return;
    var inputs=document.getElementsByTagName("input");
    if(inputs!=null){
        for(var i=0; i<inputs.length; i++){
            if(inputs[i].id.indexOf(obj.id+"_")>=0){
                document.getElementById(inputs[i].id).checked=obj.checked;
            }
        }
    }
}
</script>
</head>

<body>
<div class="title_text"><%=curName%>维护</div>

<div class="clear"><span/></div>

<table width="100%"  border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td align="right"><input name="Submit22" type="button" class="BUTTON3" value="   返回上页   " onClick="history.go(-1);"></td>
  </tr>
</table>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
	<form name="form" method="post" action="<%=modFileDo%><%=SuperPage.getQueryQ(request,"")%>" <%=strOnSubmit%>>
        <input type="hidden" name="id" value="<%=id%>">
        <input type="hidden" name="mid" value="<%=mid%>">
        <input type="hidden" name="funcid_old" value="<%=func.getFuncID()%>">
    <tr>
      <td><table width="100%" border="0" cellpadding="3" cellspacing="1" class="table_bord">
        <tr align="left" class="table_bord_ttl">
          <td><%=titletext+curName%></td>
        </tr>
        <tr class="tr_class1">
          <td><table width="100%"  border="0" cellspacing="1" cellpadding="2">
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td width="13%" align="center">功能ID：</td>
                <td width="81%"><input name="funcid" maxlength="10" type="text" id="funcid" value="<%=func.getFuncID()%>" title="模块ID">                </td>
                <td width="6%">&nbsp;</td>
              </tr>
              <tr>
                <td height="22" align="center">功能名称：</td>
                <td><input name="funcname" type="text" id="funcname" title="模块名称" value="<%=func.getFuncName()%>" size="50" maxlength="30"></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="center">&nbsp;</td>
                <td height="30"><input name="Submit" type="submit" class="BUTTON2" value=" 提 交 ">
                    <input name="Submit" type="button" class="BUTTON2" value=" 取 消 " onClick="history.back(1)"></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="center">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
          </table></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td height="5"></td>
    </tr>
<%
    if(isAdd || isMod){
%>
    <tr>
      <td><table width="100%"  border="0" cellspacing="1" cellpadding="2">
          <tr>
            <td width="64%" height="25" align="left"><font color="#0066FF"><b>权限设置</b></font></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td><div id="div_func" style="width:100%; border:1px solid #0099cc; overflow:visible; ">
          <table width="100%" border="0" cellpadding="5" cellspacing="0">
            <tr bgcolor="#FFFFFF" class="tr_jiange1">
              <td><table width="100%"  border="0" cellpadding="2" cellspacing="0">
<%
        for(int j = 0; j < list.size(); j++) {
            SysRole role=list.get(j).get(SysRole.class);
            int roleid=role.getId();
            String rolename=role.getRoleName();
            String permission=role.getPermission();
            String checked_role=list.get(j).get(DefaultBean.class).getInt("fid")>0?"checked":"";
            sql="select u.*,f.id fid from sys_user u left join sys_func_map f on (u.username=f.urname and f.fid=? and f.type=0) where u.roleid=?";
            dbconn.addParam(id);
            dbconn.addParam(roleid);
            ResultList userlist=dbconn.query(sql,true,null);
            List listUser=new ArrayList();
            for(int i = 0; i < userlist.size(); i++) {
                SysUser user=userlist.get(i).get(SysUser.class);
                int userid=user.getId();
                String username=user.getUserName();
                listUser.add(new String[]{String.valueOf(userid),username,userlist.get(i).get(DefaultBean.class).getString("fid")});
            }

%>
                  <tr>
                    <td width="91%" bgcolor="#f3f3f3"><img src="images/comm/spacer.gif" width="20" height="10">
                      <input name="check_id" type="checkbox" id="check_id_<%=rolename%>" value="role_<%=rolename%>" <%=checked_role%> class="checkbox" onClick="click_role(this)">
                        <font color="#0066CC"><b><%=rolename%></b></font></td>
                  </tr>
<%
            if(listUser.size()>0){

%>
                  <tr>
                    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="7%">&nbsp;</td>
                        <td width="93%">
<%
                for(int i = 0; i < listUser.size(); i++) {
                    String[] arrstr=(String[])listUser.get(i);
                    int _userid=SuperString.getInt(arrstr[0]);
                    String _username=SuperString.notNullTrim(arrstr[1]);
                    String checked_user=SuperString.getInt(arrstr[2])>0?"checked":"";
%>
                            <input name="check_id" type="checkbox" id="check_id_<%=rolename%>_<%=_username%>" value="<%=_username%>" <%=checked_user%> class="checkbox"> <%=_username%> &nbsp;&nbsp;
<%
                }
%>
                        </td>
                      </tr>
                    </table></td>
                  </tr>
<%

            }
        }
%>
              </table></td>
            </tr>
          </table>
      </div></td>
    </tr>
<%
    }
%>
    <tr>
      <td height="30" align="center">&nbsp;</td>
    </tr>
  </form>
</table>
</body>
</html>